package top.vanchor.myblog2back.controller.user.gameCenter;

import lombok.Data;

import java.util.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Ding
 * @create 2022/2/6 22:59
 */
public class PokerJudge {
    /**
     * 比较牌张大小的标尺
     */
    private final static String[] SORT = {"1", "0", "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};
    private final static String[] SHUNZI_SORT = {"A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3"};

    public static boolean numErrorTwo(List<Map<String, Object>> sendPoker) {
        //我们打了两张，那么判断是不是王炸
        //王炸可以压一切，所以不需要在意lastPoker是什么东西
        int n = 0;
        for (Map<String, Object> map : sendPoker) {
            if ("0".equals(String.valueOf(map.get("n"))) || "1".equals(String.valueOf(map.get("n")))) {
                n++;
            }
        }
        if (n == 2) {
            return true;
        }
        return false;
    }

    public static boolean numErrorFour(List<Map<String, Object>> sendPoker, List<Map<String, Object>> lastPoker) {
        /*
                          打了四张，首先判断四张是否一样构成炸弹
                          在判断对方是否是王炸
                          如果不是，则压上，否则压不上
                         */
        boolean isLastPokerKingBoom = false;
        int n = 0;
        for (Map<String, Object> map : lastPoker) {
            if ("0".equals(String.valueOf(map.get("n"))) || "1".equals(String.valueOf(map.get("n")))) {
                n++;
            }
        }
        if (n == 2) {
            isLastPokerKingBoom = true;
        }
        if (!isLastPokerKingBoom) {
            int m = 0;
            String firstPoker = String.valueOf(sendPoker.get(0).get("n"));
            for (Map<String, Object> map : sendPoker) {
                if (firstPoker.equals(map.get("n"))) {
                    m++;
                }
            }
            if (m == 4) {
                return true;
            }
        }
        return false;
    }

    /**
     * 1张出牌
     *
     * @param sendPoker
     * @return
     */
    public static boolean one(List<Map<String, Object>> sendPoker) {
        for (String s : SORT) {
            if (sendPoker.get(0).get("n").equals(s)) {
                //合法
                return true;
            }
        }
        return false;
    }

    /**
     * 1张压牌
     *
     * @param lastPoker
     * @param sendPoker
     * @return
     */
    public static boolean one(List<Map<String, Object>> sendPoker, List<Map<String, Object>> lastPoker) {
        int index = 0;
        int lastPokerIndex = 0;
        for (String s : SORT) {
            if (s.equals(lastPoker.get(0).get("n"))) {
                break;
            }
            lastPokerIndex++;
        }
        for (String s : SORT) {
            if (sendPoker.get(0).get("n").equals(s)) {
                //合法
                break;
            }
            index++;
        }
        if (index < lastPokerIndex) {
            //成功压牌
            return true;
        }
        return false;
    }

    /**
     * 2张出牌
     *
     * @param sendPoker
     * @return
     */
    public static boolean two(List<Map<String, Object>> sendPoker) {
        /*
            两张：王炸，对子
         */
        if (String.valueOf(sendPoker.get(0).get("n")).equals(String.valueOf(sendPoker.get(1).get("n")))) {
            //对子
            return true;
        } else {
            //王炸
            int n = 0;
            for (Map<String, Object> map : sendPoker) {
                if ("0".equals(String.valueOf(map.get("n"))) || "1".equals(String.valueOf(map.get("n")))) {
                    n++;
                }
            }
            if (n == 2) {
                return true;
            }
        }
        return false;
    }

    /**
     * 2张压牌
     *
     * @param lastPoker
     * @param sendPoker
     * @return
     */
    public static boolean two(List<Map<String, Object>> sendPoker, List<Map<String, Object>> lastPoker) {
        /*
            两张：王炸，对子
         */
        if (String.valueOf(sendPoker.get(0).get("n")).equals(String.valueOf(sendPoker.get(1).get("n")))) {
            //是对子，还要看对家出的是不是对子，紧接着我是否管的上
            if (String.valueOf(lastPoker.get(0).get("n")).equals(String.valueOf(lastPoker.get(1).get("n")))) {
                //对家也是对子，看对子大小
                int sendIndex = 0;
                int lastIndex = 0;
                int i = 0;
                for (String s : SORT) {
                    if (s.equals(String.valueOf(lastPoker.get(0).get("n")))) {
                        lastIndex = i;
                    }
                    if (s.equals(String.valueOf(sendPoker.get(0).get("n")))) {
                        sendIndex = i;
                    }
                    if (lastIndex != 0 && sendIndex != 0) {
                        break;
                    }
                    i++;
                }
                return sendIndex < lastIndex;
            }
        } else {
            //王炸
            int n = 0;
            for (Map<String, Object> map : sendPoker) {
                if ("0".equals(String.valueOf(map.get("n"))) || "1".equals(String.valueOf(map.get("n")))) {
                    n++;
                }
            }
            if (n == 2) {
                return true;
            }
        }
        return false;
    }


    public static boolean three(List<Map<String, Object>> sendPoker) {
        //三个不带，如AAA
        int n = 0;
        String firstPoker = String.valueOf(sendPoker.get(0).get("n"));
        for (Map<String, Object> map : sendPoker) {
            if (firstPoker.equals(String.valueOf(map.get("n")))) {
                n++;
            }
        }
        return n == 3;
    }

    public static boolean three(List<Map<String, Object>> sendPoker, List<Map<String, Object>> lastPoker) {
        //三个不带，如AAA
        int n = 0;
        String firstPoker = String.valueOf(sendPoker.get(0).get("n"));
        for (Map<String, Object> map : sendPoker) {
            if (firstPoker.equals(String.valueOf(map.get("n")))) {
                n++;
            }
        }
        if (n == 3) {
            int m = 0;
            String firstLastPoker = String.valueOf(lastPoker.get(0).get("n"));
            for (Map<String, Object> map : lastPoker) {
                if (firstLastPoker.equals(String.valueOf(map.get("n")))) {
                    m++;
                }
            }
            if (m == 3) {
                //对家也是三个，看三个大小
                int sendIndex = 0;
                int lastIndex = 0;
                int i = 0;
                for (String s : SORT) {
                    if (s.equals(String.valueOf(lastPoker.get(0).get("n")))) {
                        lastIndex = i;
                    }
                    if (s.equals(String.valueOf(sendPoker.get(0).get("n")))) {
                        sendIndex = i;
                    }
                    if (lastIndex != 0 && sendIndex != 0) {
                        break;
                    }
                    i++;
                }
                if (sendIndex < lastIndex) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean four(List<Map<String, Object>> sendPoker) {
        //四张：炸弹、三带一
        //靶向判断炸弹
        int m = 0;
        String firstPoker = String.valueOf(sendPoker.get(0).get("n"));
        for (Map<String, Object> map : sendPoker) {
            if (firstPoker.equals(map.get("n"))) {
                m++;
            }
        }
        if (m == 4) {
            //是炸弹，出就行了
            return true;
        }
        //执行此处说明不是炸弹，靶向判断三带一
        int n = 0;
        ArrayList<String> str = new ArrayList<>();
        str.add(String.valueOf(sendPoker.get(0).get("n")));
        str.add(String.valueOf(sendPoker.get(1).get("n")));
        str.add(String.valueOf(sendPoker.get(2).get("n")));
        str.add(String.valueOf(sendPoker.get(3).get("n")));
        for (int i = 0; i < str.size(); i++) {
            for (int j = 0; j < str.size(); j++) {
                if (i != j && str.get(i).equals(str.get(j))) {
                    str.remove(i);
                }
            }
        }
        if (str.size() == 2) {
            //去重后，只要剩俩，就对！
            return true;
        }
        //如果什么都不是或者不合规则，就直接false
        return false;
    }

    public static boolean four(List<Map<String, Object>> sendPoker, List<Map<String, Object>> lastPoker) {
        //四张：炸弹、三带一
        //靶向判断炸弹
        int m = 0;
        String firstPoker = String.valueOf(sendPoker.get(0).get("n"));
        for (Map<String, Object> map : sendPoker) {
            if (firstPoker.equals(map.get("n"))) {
                m++;
            }
        }
        if (m == 4) {
            //是炸弹，在判断上家是不是炸弹
            int n = 0;
            String firstLastPoker = String.valueOf(lastPoker.get(0).get("n"));
            for (Map<String, Object> map : lastPoker) {
                if (firstLastPoker.equals(map.get("n"))) {
                    n++;
                }
            }
            if (n < 4) {
                //对方不是炸弹，直接T了
                return true;
            } else {
                //否则必然是炸弹，比较大小即可
                //对家也是炸弹，比较大小
                int sendIndex = 0;
                int lastIndex = 0;
                int i = 0;
                for (String s : SORT) {
                    if (s.equals(String.valueOf(lastPoker.get(0).get("n")))) {
                        lastIndex = i;
                    }
                    if (s.equals(String.valueOf(sendPoker.get(0).get("n")))) {
                        sendIndex = i;
                    }
                    if (lastIndex != 0 && sendIndex != 0) {
                        break;
                    }
                    i++;
                }
                System.err.println(sendIndex + ".." + lastIndex);
                return sendIndex < lastIndex;
            }
        }
        //执行此处说明不是炸弹，靶向判断三带一
        //先判断对家是不是炸弹，是炸弹没得玩
        int p = 0;
        String firstLastPoker = String.valueOf(lastPoker.get(0).get("n"));
        for (Map<String, Object> map : lastPoker) {
            if (firstLastPoker.equals(map.get("n"))) {
                p++;
            }
        }
        if (p == 4) {
            //对方是炸弹，直接false，你管不过
            return false;
        }
        //执行此处说明对家也是三带一，先看咱的三带一
        String sendMultiplePoker = "";
        ArrayList<String> str = new ArrayList<>();
        str.add(String.valueOf(sendPoker.get(0).get("n")));
        str.add(String.valueOf(sendPoker.get(1).get("n")));
        str.add(String.valueOf(sendPoker.get(2).get("n")));
        str.add(String.valueOf(sendPoker.get(3).get("n")));
        for (int i = 0; i < str.size(); i++) {
            for (int j = 0; j < str.size(); j++) {
                if (i != j && str.get(i).equals(str.get(j))) {
                    sendMultiplePoker = str.get(i);
                    str.remove(i);
                }
            }
        }
        if (str.size() == 2) {
            //去重后，只要剩俩，就对！
            String lastMultiplePoker = "";
            ArrayList<String> str1 = new ArrayList<>();
            str1.add(String.valueOf(lastPoker.get(0).get("n")));
            str1.add(String.valueOf(lastPoker.get(1).get("n")));
            str1.add(String.valueOf(lastPoker.get(2).get("n")));
            str1.add(String.valueOf(lastPoker.get(3).get("n")));
            for (int i = 0; i < str1.size(); i++) {
                for (int j = 0; j < str1.size(); j++) {
                    if (i != j && str1.get(i).equals(str1.get(j))) {
                        lastMultiplePoker = str1.get(i);
                        str1.remove(i);
                    }
                }
            }
            if (str1.size() == 2) {
                //去重后，只要剩俩，就对！
                //比较三张索引
                //否则必然是炸弹，比较大小即可
                //对家也是炸弹，比较大小
                int sendIndex = 0;
                int lastIndex = 0;
                int i = 0;
                for (String s : SORT) {
                    if (s.equals(lastMultiplePoker)) {
                        lastIndex = i;
                    }
                    if (s.equals(sendMultiplePoker)) {
                        sendIndex = i;
                    }
                    if (lastIndex != 0 && sendIndex != 0) {
                        break;
                    }
                    i++;
                }
                if (sendIndex < lastIndex) {
                    return true;
                } else {
                    return false;
                }
            }
        }
        //如果什么都不是或者不合规则，就直接false
        return false;
    }

    /**
     * 五张牌-出牌
     * 三带一对、顺子
     *
     * @param sendPoker
     * @return
     */
    public static boolean five(List<Map<String, Object>> sendPoker) {
        //首先判断是否是顺子,索引判断
        ArrayList<Integer> sendPokerIndex = new ArrayList<>();
        for (Map<String, Object> map : sendPoker) {
            int index = 0;
            for (String s : SHUNZI_SORT) {
                if (s.equals(map.get("n"))) {
                    sendPokerIndex.add(index);
                    break;
                }
                index++;
            }
        }
        if (sendPokerIndex.size() == 5) {
            //排序（索引小->大），注意，本系统逻辑中索引越小代表的扑克牌越大
            Collections.sort(sendPokerIndex);
            //判断索引是否是递增即可
            int i = sendPokerIndex.get(0);
            int n = 0;
            while (n < 5) {
                if (i != sendPokerIndex.get(n)) {
                    //索引不是递增
                    break;
                }
                i++;
                n++;
            }
            if (n == 5) {
                //是顺子，走！
                return true;
            }
        }
        //执行此处，说明不是顺子，靶向判断三带一对
        int n = 0;
        ArrayList<String> str = new ArrayList<>();
        str.add(String.valueOf(sendPoker.get(0).get("n")));
        str.add(String.valueOf(sendPoker.get(1).get("n")));
        str.add(String.valueOf(sendPoker.get(2).get("n")));
        str.add(String.valueOf(sendPoker.get(3).get("n")));
        str.add(String.valueOf(sendPoker.get(4).get("n")));
        for (int i = 0; i < str.size(); i++) {
            for (int j = 0; j < str.size(); j++) {
                if (i != j && str.get(i).equals(str.get(j))) {
                    str.remove(i);
                }
            }
        }
        if (str.size() == 2) {
            //去重后，剩俩
            @Data
            class Temp{
                //拥有数
                private Integer haveNum;
                //牌值
                private String strValue;
            }
            Temp t1 = new Temp();
            Temp t2 = new Temp();
            for (Map<String, Object> map : sendPoker) {
                if (t1.getHaveNum() == null){
                    t1.setHaveNum(1);
                    t1.setStrValue(String.valueOf(map.get("n")));
                }else{
                    if (t1.getStrValue().equals(String.valueOf(map.get("n")))){
                        t1.setHaveNum(t1.getHaveNum() + 1);
                    }else{
                        if (t2.getHaveNum() == null){
                            t2.setHaveNum(1);
                            t2.setStrValue(String.valueOf(map.get("n")));
                        }else{
                            //肯定两张了，所以不需要继续判断
                            t2.setHaveNum(t2.getHaveNum() + 1);
                        }
                    }
                }
            }
//            String maxNumPoker = t1.getHaveNum() > t2.getHaveNum()?t1.getStrValue():t2.getStrValue();
            return t1.getHaveNum()==3&&t2.getHaveNum()==2 || t1.getHaveNum()==2&&t2.getHaveNum()==3;
        }
        return false;
    }

    /**
     * 五张牌-压牌
     * 三带一对、顺子
     *
     * @param sendPoker
     * @param lastPoker
     * @return
     */
    public static boolean five(List<Map<String, Object>> sendPoker, List<Map<String, Object>> lastPoker) {
        //首先判断是否是顺子,索引判断
        ArrayList<Integer> sendPokerIndex = new ArrayList<>();
        for (Map<String, Object> map : sendPoker) {
            int index = 0;
            for (String s : SHUNZI_SORT) {
                if (s.equals(map.get("n"))) {
                    sendPokerIndex.add(index);
                    break;
                }
                index++;
            }
        }
        if (sendPokerIndex.size() == 5) {
            //排序（索引小->大），注意，本系统逻辑中索引越小代表的扑克牌越大
            Collections.sort(sendPokerIndex);
            //判断索引是否是递增即可
            int i = sendPokerIndex.get(0);
            int n = 0;
            while (n < 5) {
                if (i != sendPokerIndex.get(n)) {
                    //索引不是递增
                    break;
                }
                i++;
                n++;
            }
            if (n == 5) {
                //是顺子，再看对家
                ArrayList<Integer> lastPokerIndex = new ArrayList<>();
                for (Map<String, Object> map : lastPoker) {
                    int index = 0;
                    for (String s : SHUNZI_SORT) {
                        if (s.equals(map.get("n"))) {
                            lastPokerIndex.add(index);
                            break;
                        }
                        index++;
                    }
                }
                if (lastPokerIndex.size() == 5) {
                    //排序（索引小->大），注意，本系统逻辑中索引越小代表的扑克牌越大
                    Collections.sort(lastPokerIndex);
                    //判断索引是否是递增即可
                    int ii = lastPokerIndex.get(0);
                    int nn = 0;
                    while (nn < 5) {
                        if (ii != lastPokerIndex.get(nn)) {
                            //索引不是递增
                            break;
                        }
                        ii++;
                        nn++;
                    }
                    if (nn == 5) {
                        //是顺子，比较大小
                        if (sendPokerIndex.get(0) < lastPokerIndex.get(0)){
                            return true;
                        }else{
                            return false;
                        }
                    }
                }
            }
        }
        //执行此处，说明不是顺子，靶向判断三带一对
        ArrayList<String> str = new ArrayList<>();
        str.add(String.valueOf(sendPoker.get(0).get("n")));
        str.add(String.valueOf(sendPoker.get(1).get("n")));
        str.add(String.valueOf(sendPoker.get(2).get("n")));
        str.add(String.valueOf(sendPoker.get(3).get("n")));
        str.add(String.valueOf(sendPoker.get(4).get("n")));
        for (int i = 0; i < str.size(); i++) {
            for (int j = 0; j < str.size(); j++) {
                if (i != j && str.get(i).equals(str.get(j))) {
                    str.remove(i);
                }
            }
        }
        if (str.size() == 2) {
            //去重后，剩俩
            Temp t1 = new Temp();
            Temp t2 = new Temp();
            for (Map<String, Object> map : sendPoker) {
                if (t1.getHaveNum() == null){
                    t1.setHaveNum(1);
                    t1.setStrValue(String.valueOf(map.get("n")));
                }else{
                    if (t1.getStrValue().equals(String.valueOf(map.get("n")))){
                        t1.setHaveNum(t1.getHaveNum() + 1);
                    }else{
                        if (t2.getHaveNum() == null){
                            t2.setHaveNum(1);
                            t2.setStrValue(String.valueOf(map.get("n")));
                        }else{
                            //肯定两张了，所以不需要继续判断
                            t2.setHaveNum(t2.getHaveNum() + 1);
                        }
                    }
                }
            }
            String maxNumPoker = t1.getHaveNum() > t2.getHaveNum()?t1.getStrValue():t2.getStrValue();
            boolean isOk =  t1.getHaveNum()==3&&t2.getHaveNum()==2 || t1.getHaveNum()==2&&t2.getHaveNum()==3;
            if (isOk){
                ArrayList<String> str1 = new ArrayList<>();
                str1.add(String.valueOf(lastPoker.get(0).get("n")));
                str1.add(String.valueOf(lastPoker.get(1).get("n")));
                str1.add(String.valueOf(lastPoker.get(2).get("n")));
                str1.add(String.valueOf(lastPoker.get(3).get("n")));
                str1.add(String.valueOf(lastPoker.get(4).get("n")));
                for (int i = 0; i < str1.size(); i++) {
                    for (int j = 0; j < str1.size(); j++) {
                        if (i != j && str1.get(i).equals(str1.get(j))) {
                            str1.remove(i);
                        }
                    }
                }
                if (str1.size() == 2) {
                    //去重后，剩俩
                    t1 = new Temp();
                    t2 = new Temp();
                    for (Map<String, Object> map : lastPoker) {
                        if (t1.getHaveNum() == null){
                            t1.setHaveNum(1);
                            t1.setStrValue(String.valueOf(map.get("n")));
                        }else{
                            if (t1.getStrValue().equals(String.valueOf(map.get("n")))){
                                t1.setHaveNum(t1.getHaveNum() + 1);
                            }else{
                                if (t2.getHaveNum() == null){
                                    t2.setHaveNum(1);
                                    t2.setStrValue(String.valueOf(map.get("n")));
                                }else{
                                    //肯定两张了，所以不需要继续判断
                                    t2.setHaveNum(t2.getHaveNum() + 1);
                                }
                            }
                        }
                    }
                    String maxNumPoker1 = t1.getHaveNum() > t2.getHaveNum()?t1.getStrValue():t2.getStrValue();
                    boolean isOk1 =  t1.getHaveNum()==3&&t2.getHaveNum()==2 || t1.getHaveNum()==2&&t2.getHaveNum()==3;
                    if (isOk1){
                        int sendIndex = 0;
                        int lastIndex = 0;
                        int i = 0;
                        for (String s : SORT) {
                            if (s.equals(maxNumPoker1)) {
                                lastIndex = i;
                            }
                            if (s.equals(maxNumPoker)) {
                                sendIndex = i;
                            }
                            if (lastIndex != 0 && sendIndex != 0) {
                                break;
                            }
                            i++;
                        }
                        if (sendIndex < lastIndex) {
                            return true;
                        } else {
                            return false;
                        }
                    }
                }
            }
        }
        return false;
    }

    /**
     * 六张牌出牌
     * 三顺（飞机不带翅膀）--2，顺子--6，连对--3，四带二--3
     * @param sendPoker
     * @return
     */
    public static boolean six(List<Map<String, Object>> sendPoker) {
        //执去重，查看多少种牌
        ArrayList<String> str = new ArrayList<>();
        for (Map<String, Object> map : sendPoker) {
            str.add(String.valueOf(map.get("n")));
        }
        for (int i = 0; i < str.size(); i++) {
            for (int j = 0; j < str.size(); j++) {
                if (i != j && str.get(i).equals(str.get(j))) {
                    str.remove(i);
                }
            }
        }
        if (str.size() == 6){
            //去重后和去重前一样，说明要么是顺子ABCDEF，要么啥也不是
            ArrayList<Integer> sendPokerIndex = new ArrayList<>();
            for (Map<String, Object> map : sendPoker) {
                int index = 0;
                for (String s : SHUNZI_SORT) {
                    if (s.equals(map.get("n"))) {
                        sendPokerIndex.add(index);
                        break;
                    }
                    index++;
                }
            }
            //排序（索引小->大），注意，本系统逻辑中索引越小代表的扑克牌越大
            Collections.sort(sendPokerIndex);
            //判断索引是否是递增即可
            int i = sendPokerIndex.get(0);
            int n = 0;
            while (n < 6) {
                if (i != sendPokerIndex.get(n)) {
                    //索引不是递增
                    break;
                }
                i++;
                n++;
            }
            if (n == 6) {
                //是顺子，走！
                return true;
            }
        }else if (str.size() == 2){
            //靶向判断-飞机不带AAABBB或者四带二的特殊牌型：BAAAAB
            Temp t1 = new Temp();
            Temp t2 = new Temp();
            for (Map<String, Object> map : sendPoker) {
                if (t1.getHaveNum() == null){
                    t1.setHaveNum(1);
                    t1.setStrValue(String.valueOf(map.get("n")));
                }else{
                    if (t1.getStrValue().equals(String.valueOf(map.get("n")))){
                        t1.setHaveNum(t1.getHaveNum() + 1);
                    }else{
                        if (t2.getHaveNum() == null){
                            t2.setHaveNum(1);
                            t2.setStrValue(String.valueOf(map.get("n")));
                        }else{
                            //肯定两张了，所以不需要继续判断
                            t2.setHaveNum(t2.getHaveNum() + 1);
                        }
                    }
                }
            }
            ArrayList<Integer> sendPokerIndex = new ArrayList<>();
            for (Map<String, Object> map : sendPoker) {
                int index = 0;
                for (String s : SHUNZI_SORT) {
                    if (s.equals(map.get("n"))) {
                        sendPokerIndex.add(index);
                        break;
                    }
                    index++;
                }
            }
            if (t2.getHaveNum().equals(t1.getHaveNum()) && t1.getHaveNum() == 3){
                //是飞机不带翅膀，走！
                return sendPokerIndex.get(0) + 1 == sendPokerIndex.get(5) || sendPokerIndex.get(5) + 1 == sendPokerIndex.get(0);
            }else{
                ArrayList<Integer> mySort = new ArrayList<>();
                mySort.add(t1.getHaveNum());
                mySort.add(t2.getHaveNum());
                Collections.sort(mySort);
                if (mySort.get(mySort.size()-1) == 4){
                    //四带二，必然成功
                    return true;
                }
            }
        }else if (str.size() == 3){
            //两种可能：连对AABBCC，四带二AAAABC
            Temp t1 = new Temp();
            Temp t2 = new Temp();
            Temp t3 = new Temp();
            for (Map<String, Object> map : sendPoker) {
                if (t1.getHaveNum() == null){
                    t1.setHaveNum(1);
                    t1.setStrValue(String.valueOf(map.get("n")));
                }else{
                    if (t1.getStrValue().equals(String.valueOf(map.get("n")))){
                        t1.setHaveNum(t1.getHaveNum() + 1);
                    }else{
                        if (t2.getHaveNum() == null){
                            t2.setHaveNum(1);
                            t2.setStrValue(String.valueOf(map.get("n")));
                        }else{
                            if (t2.getStrValue().equals(String.valueOf(map.get("n")))){
                                t2.setHaveNum(t2.getHaveNum() + 1);
                            }else{
                                if (t3.getHaveNum() == null){
                                    t3.setHaveNum(1);
                                    t3.setStrValue(String.valueOf(map.get("n")));
                                }else{
                                    //肯定两张了，所以不需要继续判断
                                    t3.setHaveNum(t3.getHaveNum() + 1);
                                }
                            }
                        }
                    }
                }
            }
            ArrayList<Integer> mySort = new ArrayList<>();
            mySort.add(t1.getHaveNum());
            mySort.add(t2.getHaveNum());
            mySort.add(t3.getHaveNum());
            Collections.sort(mySort);
            if (mySort.get(mySort.size()-1) == 4){
                //四带二，必然成功
                return true;
            }else{
                //可能是连对
                ArrayList<Integer> sendPokerIndex = new ArrayList<>();
                for (String n1 : str) {
                    int index = 0;
                    for (String s : SHUNZI_SORT) {
                        if (s.equals(n1)) {
                            sendPokerIndex.add(index);
                            break;
                        }
                        index++;
                    }
                }
                //排序（索引小->大），注意，本系统逻辑中索引越小代表的扑克牌越大
                Collections.sort(sendPokerIndex);
                //判断索引是否是递增即可
                int i = sendPokerIndex.get(0);
                int n = 0;
                while (n < 3) {
                    if (i != sendPokerIndex.get(n)) {
                        //索引不是递增
                        break;
                    }
                    i++;
                    n++;
                }
                //是顺子，走！
                return n == 3;
            }
        }
        return false;
    }

    /**
     * 六张牌--压牌
     * @param sendPoker
     * @param lastPoker
     * @return
     */
    public static boolean six(List<Map<String, Object>> sendPoker,List<Map<String, Object>> lastPoker) {
        //执去重，查看多少种牌
        ArrayList<String> str = new ArrayList<>();
        ArrayList<String> lastStr = new ArrayList<>();
        for (Map<String, Object> map : sendPoker) {
            str.add(String.valueOf(map.get("n")));
        }
        for (Map<String, Object> map : lastPoker) {
            lastStr.add(String.valueOf(map.get("n")));
        }
        for (int i = 0; i < str.size(); i++) {
            for (int j = 0; j < str.size(); j++) {
                if (i != j && str.get(i).equals(str.get(j))) {
                    str.remove(i);
                }
            }
        }
        for (int i = 0; i < lastStr.size(); i++) {
            for (int j = 0; j < lastStr.size(); j++) {
                if (i != j && lastStr.get(i).equals(lastStr.get(j))) {
                    lastStr.remove(i);
                }
            }
        }
        if (str.size() == 6){
            //去重后和去重前一样，说明要么是顺子ABCDEF，要么啥也不是
            ArrayList<Integer> sendPokerIndex = new ArrayList<>();
            for (Map<String, Object> map : sendPoker) {
                int index = 0;
                for (String s : SHUNZI_SORT) {
                    if (s.equals(map.get("n"))) {
                        sendPokerIndex.add(index);
                        break;
                    }
                    index++;
                }
            }
            //排序（索引小->大），注意，本系统逻辑中索引越小代表的扑克牌越大
            Collections.sort(sendPokerIndex);
            //判断索引是否是递增即可
            int i = sendPokerIndex.get(0);
            int n = 0;
            while (n < 6) {
                if (i != sendPokerIndex.get(n)) {
                    //索引不是递增
                    break;
                }
                i++;
                n++;
            }
            if (n == 6) {
                //是顺子，看对面是顺子不
                ArrayList<String> str1 = new ArrayList<>();
                for (Map<String, Object> map : lastPoker) {
                    str1.add(String.valueOf(map.get("n")));
                }
                for (int ii = 0; ii < str1.size(); ii++) {
                    for (int jj = 0; jj < str1.size(); jj++) {
                        if (ii != jj && str1.get(ii).equals(str1.get(jj))) {
                            str1.remove(ii);
                        }
                    }
                }
                if (str1.size() == 6){
                    //去重后和去重前一样，说明要么是顺子ABCDEF，要么啥也不是
                    ArrayList<Integer> lastPokerIndex = new ArrayList<>();
                    for (Map<String, Object> map : lastPoker) {
                        int index = 0;
                        for (String s : SHUNZI_SORT) {
                            if (s.equals(map.get("n"))) {
                                lastPokerIndex.add(index);
                                break;
                            }
                            index++;
                        }
                    }
                    //排序（索引小->大），注意，本系统逻辑中索引越小代表的扑克牌越大
                    Collections.sort(lastPokerIndex);
                    //判断索引是否是递增即可
                    int ii = lastPokerIndex.get(0);
                    int nn = 0;
                    while (nn < 6) {
                        if (ii != lastPokerIndex.get(nn)) {
                            //索引不是递增
                            break;
                        }
                        ii++;
                        nn++;
                    }
                    if (nn == 6) {
                        //上家牌也是顺子，压上就对
                        return sendPokerIndex.get(0) < lastPokerIndex.get(0);
                    }
                }
            }
        }else if (str.size() == 2){
            //靶向判断-飞机不带AAABBB或者四带二的特殊牌型：BAAAAB
            Temp t1 = new Temp();
            Temp t2 = new Temp();
            for (Map<String, Object> map : sendPoker) {
                if (t1.getHaveNum() == null){
                    t1.setHaveNum(1);
                    t1.setStrValue(String.valueOf(map.get("n")));
                }else{
                    if (t1.getStrValue().equals(String.valueOf(map.get("n")))){
                        t1.setHaveNum(t1.getHaveNum() + 1);
                    }else{
                        if (t2.getHaveNum() == null){
                            t2.setHaveNum(1);
                            t2.setStrValue(String.valueOf(map.get("n")));
                        }else{
                            //肯定两张了，所以不需要继续判断
                            t2.setHaveNum(t2.getHaveNum() + 1);
                        }
                    }
                }
            }
            ArrayList<Integer> sendPokerIndex = new ArrayList<>();
            for (Map<String, Object> map : sendPoker) {
                int index = 0;
                for (String s : SHUNZI_SORT) {
                    if (s.equals(map.get("n"))) {
                        sendPokerIndex.add(index);
                        break;
                    }
                    index++;
                }
            }
            if (t2.getHaveNum().equals(t1.getHaveNum()) && t1.getHaveNum() == 3){
                if (sendPokerIndex.get(0) + 1 == sendPokerIndex.get(5) || sendPokerIndex.get(5) + 1 == sendPokerIndex.get(0)){
                    //是飞机不带翅膀，判断上家是不是
                    t1 = new Temp();
                    t2 = new Temp();
                    for (Map<String, Object> map : lastPoker) {
                        if (t1.getHaveNum() == null){
                            t1.setHaveNum(1);
                            t1.setStrValue(String.valueOf(map.get("n")));
                        }else{
                            if (t1.getStrValue().equals(String.valueOf(map.get("n")))){
                                t1.setHaveNum(t1.getHaveNum() + 1);
                            }else{
                                if (t2.getHaveNum() == null){
                                    t2.setHaveNum(1);
                                    t2.setStrValue(String.valueOf(map.get("n")));
                                }else{
                                    //肯定两张了，所以不需要继续判断
                                    t2.setHaveNum(t2.getHaveNum() + 1);
                                }
                            }
                        }
                    }
                    ArrayList<Integer> lastPokerIndex = new ArrayList<>();
                    for (Map<String, Object> map : lastPoker) {
                        int index = 0;
                        for (String s : SHUNZI_SORT) {
                            if (s.equals(map.get("n"))) {
                                lastPokerIndex.add(index);
                                break;
                            }
                            index++;
                        }
                    }
                    if (t2.getHaveNum().equals(t1.getHaveNum()) && t1.getHaveNum() == 3){
                        //是飞机不带翅膀，判断上家是不是
                        if (lastPokerIndex.get(0) + 1 == lastPokerIndex.get(5) || lastPokerIndex.get(5) + 1 == lastPokerIndex.get(0)){
                            //上家也是飞机不带翅膀，判断索引即可
                            return sendPokerIndex.get(0) < lastPokerIndex.get(0);
                        }
                    }
                }
            }else{
                ArrayList<Integer> mySort = new ArrayList<>();
                mySort.add(t1.getHaveNum());
                mySort.add(t2.getHaveNum());
                Collections.sort(mySort);
                if (mySort.get(mySort.size()-1) == 4){
                    //四带二，找出四张的那个值对应的index
                    String strDemo = t1.getHaveNum() == 4?t1.getStrValue():t2.getStrValue();
                    int index = 0;
                    for (String s : SORT) {
                        if (s.equals(strDemo)){
                            break;
                        }
                        index++;
                    }
                    //再看看对方啥牌型
                    t1 = new Temp();
                    t2 = new Temp();
                    Temp t3 = new Temp();
                    for (Map<String, Object> map : lastPoker) {
                        if (t1.getHaveNum() == null){
                            t1.setHaveNum(1);
                            t1.setStrValue(String.valueOf(map.get("n")));
                        }else{
                            if (t1.getStrValue().equals(String.valueOf(map.get("n")))){
                                t1.setHaveNum(t1.getHaveNum() + 1);
                            }else{
                                if (t2.getHaveNum() == null){
                                    t2.setHaveNum(1);
                                    t2.setStrValue(String.valueOf(map.get("n")));
                                }else{
                                    if (t2.getStrValue().equals(String.valueOf(map.get("n")))){
                                        t2.setHaveNum(t2.getHaveNum() + 1);
                                    }else{
                                        if (t3.getHaveNum() == null){
                                            t3.setHaveNum(1);
                                            t3.setStrValue(String.valueOf(map.get("n")));
                                        }else{
                                            //肯定两张了，所以不需要继续判断
                                            t3.setHaveNum(t3.getHaveNum() + 1);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    ArrayList<Integer> mySort1 = new ArrayList<>();
                    mySort1.add(t1.getHaveNum());
                    mySort1.add(t2.getHaveNum());
                    mySort1.add(t3.getHaveNum());
                    Collections.sort(mySort1);
                    if (mySort1.get(mySort1.size()-1) == 4){
                        //四带二，找出四张的那个值对应的index
                        String strDemo1 = t1.getHaveNum() == 4?t1.getStrValue():t2.getHaveNum() == 4?t2.getStrValue():t3.getStrValue();
                        int index1 = 0;
                        for (String s : SORT) {
                            if (s.equals(strDemo1)){
                                break;
                            }
                            index1++;
                        }
                        return index<index1;
                    }
                }
            }
        }else if (str.size() == 3){
            //两种可能：连对AABBCC，四带二AAAABC
            Temp t1 = new Temp();
            Temp t2 = new Temp();
            Temp t3 = new Temp();
            for (Map<String, Object> map : sendPoker) {
                if (t1.getHaveNum() == null){
                    t1.setHaveNum(1);
                    t1.setStrValue(String.valueOf(map.get("n")));
                }else{
                    if (t1.getStrValue().equals(String.valueOf(map.get("n")))){
                        t1.setHaveNum(t1.getHaveNum() + 1);
                    }else{
                        if (t2.getHaveNum() == null){
                            t2.setHaveNum(1);
                            t2.setStrValue(String.valueOf(map.get("n")));
                        }else{
                            if (t2.getStrValue().equals(String.valueOf(map.get("n")))){
                                t2.setHaveNum(t2.getHaveNum() + 1);
                            }else{
                                if (t3.getHaveNum() == null){
                                    t3.setHaveNum(1);
                                    t3.setStrValue(String.valueOf(map.get("n")));
                                }else{
                                    //肯定两张了，所以不需要继续判断
                                    t3.setHaveNum(t3.getHaveNum() + 1);
                                }
                            }
                        }
                    }
                }
            }
            ArrayList<Integer> mySort = new ArrayList<>();
            mySort.add(t1.getHaveNum());
            mySort.add(t2.getHaveNum());
            mySort.add(t3.getHaveNum());
            Collections.sort(mySort);
            if (mySort.get(mySort.size()-1) == 4){
                //四带二，看对面是不是
                Temp t4 = new Temp();
                Temp t5 = new Temp();
                Temp t6 = new Temp();
                for (Map<String, Object> map : lastPoker) {
                    if (t4.getHaveNum() == null){
                        t4.setHaveNum(1);
                        t4.setStrValue(String.valueOf(map.get("n")));
                    }else{
                        if (t4.getStrValue().equals(String.valueOf(map.get("n")))){
                            t4.setHaveNum(t4.getHaveNum() + 1);
                        }else{
                            if (t5.getHaveNum() == null){
                                t5.setHaveNum(1);
                                t5.setStrValue(String.valueOf(map.get("n")));
                            }else{
                                if (t5.getStrValue().equals(String.valueOf(map.get("n")))){
                                    t5.setHaveNum(t5.getHaveNum() + 1);
                                }else{
                                    if (t6.getHaveNum() == null){
                                        t6.setHaveNum(1);
                                        t6.setStrValue(String.valueOf(map.get("n")));
                                    }else{
                                        //肯定两张了，所以不需要继续判断
                                        t6.setHaveNum(t6.getHaveNum() + 1);
                                    }
                                }
                            }
                        }
                    }
                }
                ArrayList<Integer> mySort1 = new ArrayList<>();
                mySort1.add(t4.getHaveNum());
                mySort1.add(t5.getHaveNum());
                if (t6.getHaveNum() != null){
                    mySort1.add(t6.getHaveNum());
                }
                System.err.println(mySort1);
                Collections.sort(mySort1);
                if (mySort1.get(mySort1.size()-1) == 4){
                    //也是四带二，接着判断大小
                    System.err.println("都是四带二");
                    String sendPokerTemp = "";
                    String lastPokerTemp = "";
                    int sendPokerIndex = 0;
                    int lastPokerIndex = 0;
                    if (t1.getHaveNum() == 4){
                        sendPokerTemp = t1.getStrValue();
                    }else if (t2.getHaveNum() == 4){
                        sendPokerTemp = t2.getStrValue();
                    }else if(t3.getHaveNum() == 4){
                        sendPokerTemp = t3.getStrValue();
                    }

                    if (t4.getHaveNum() == 4){
                        lastPokerTemp = t4.getStrValue();
                    }else if (t5.getHaveNum() == 4){
                        lastPokerTemp = t5.getStrValue();
                    }else if(t6.getHaveNum()!=null &&t6.getHaveNum() == 4){
                        lastPokerTemp = t6.getStrValue();
                    }
                    System.err.println(sendPokerTemp);
                    System.err.println(lastPokerTemp);
                    int index = 0;
                    for (String s : SORT) {
                        if (s.equals(sendPokerTemp)){
                            sendPokerIndex = index;
                            break;
                        }
                        index++;
                    }
                    index = 0;
                    for (String s : SORT) {
                        if (s.equals(lastPokerTemp)){
                            lastPokerIndex = index;
                            break;
                        }
                        index++;
                    }
                    return sendPokerIndex < lastPokerIndex;
                }
            }else{
                //是连对吗?
                ArrayList<Integer> sendPokerIndex = new ArrayList<>();
                for (String n1 : str) {
                    int index = 0;
                    for (String s : SHUNZI_SORT) {
                        if (s.equals(n1)) {
                            sendPokerIndex.add(index);
                            break;
                        }
                        index++;
                    }
                }
                //排序（索引小->大），注意，本系统逻辑中索引越小代表的扑克牌越大
                Collections.sort(sendPokerIndex);
                //判断索引是否是递增即可
                int i = sendPokerIndex.get(0);
                int n = 0;
                while (n < 3) {
                    if (i != sendPokerIndex.get(n)) {
                        //索引不是递增
                        break;
                    }
                    i++;
                    n++;
                }
                //是顺子，看上家
                if (n == 3 && lastStr.size() == 3){
                    ArrayList<Integer> lastPokerIndex = new ArrayList<>();
                    for (String n1 : str) {
                        int index = 0;
                        for (String s : SHUNZI_SORT) {
                            if (s.equals(n1)) {
                                lastPokerIndex.add(index);
                                break;
                            }
                            index++;
                        }
                    }
                    //排序（索引小->大），注意，本系统逻辑中索引越小代表的扑克牌越大
                    Collections.sort(lastPokerIndex);
                    //判断索引是否是递增即可
                    int ii = lastPokerIndex.get(0);
                    int nn = 0;
                    while (nn < 3) {
                        if (ii != lastPokerIndex.get(nn)) {
                            //索引不是递增
                            break;
                        }
                        ii++;
                        nn++;
                    }
                    return nn == 3;
                }
            }
        }
        return false;
    }

    public static boolean one10(List<Map<String, Object>> sendPoker) {
        return false;
    }

    public static boolean one112(List<Map<String, Object>> sendPoker) {
        return false;
    }public static boolean one100(List<Map<String, Object>> sendPoker) {
        return false;
    }

    public static boolean one11452(List<Map<String, Object>> sendPoker) {
        return false;
    }public static boolean one104(List<Map<String, Object>> sendPoker) {
        return false;
    }

    public static boolean one117(List<Map<String, Object>> sendPoker) {
        return false;
    }

}

@Data
class Temp{
    //拥有数
    private Integer haveNum;
    //牌值
    private String strValue;
}